#include <iostream>
#include <string>
#include "Student.h"
#include <fstream>//c++文件流头文件
using namespace std;

extern vector<Student> students; // 全局变量在main文件中声明，在task2文件中赋值

// 3、将相关信息以文件方式保存到本地硬盘中
void task3()
{
    // 创建文件流对象，用于写入学生及其分配的小车信息
    ofstream studentCarFile("D:\\AllFile\\DeskTop\\car_software\\code\\exercise1\\data\\students_and_cars.txt");
    if (!studentCarFile.is_open()) {
        cerr << "无法打开文件 students_and_cars.txt" << endl;
        return;
    }

    // 遍历students向量，写入每名学生及其小车的信息
    for (const Student& student : students) {
        studentCarFile << "学生学号: " << student.id << endl;
        studentCarFile << "学生姓名: " << student.name << endl;
        studentCarFile << "被分配的小车编号: " << student.car.id << endl;
        studentCarFile << "底盘编号: " << student.car.underpan.id << endl;
        studentCarFile << "底盘型号: " << student.car.underpan.model << endl;
        studentCarFile << "轴距: " << student.car.underpan.wheelbase << "mm" << endl;
        studentCarFile << "轮距: " << student.car.underpan.track_width << "mm" << endl;
        studentCarFile << "最小离地间隙: " << student.car.underpan.ground_clearance << "mm" << endl;
        studentCarFile << "最小转弯半径: " << student.car.underpan.turning_radius << "m" << endl;
        studentCarFile << "驱动形式: " << student.car.underpan.drive_form << endl;
        studentCarFile << "最大行程: " << student.car.underpan.max_range << "KM" << endl;
        for (const Tire& tire : student.car.underpan.tires) {
            studentCarFile << "轮胎型号: " << tire.type << ", 尺寸: " << tire.size << endl;
        }
        studentCarFile << "AGX套件型号: " << student.car.agx.model << endl;
        studentCarFile << "AI性能: " << student.car.agx.aiPerformance << " TOPS" << endl;
        studentCarFile << "CUDA核心数: " << student.car.agx.cudaCores << endl;
        studentCarFile << "Tensor核心数: " << student.car.agx.tensorCores << endl;
        studentCarFile << "显存: " << student.car.agx.memory << "GB" << endl;
        studentCarFile << "存储: " << student.car.agx.storage << "GB" << endl;
        studentCarFile << "双目摄像头型号: " << student.car.camera.model << endl;
        studentCarFile << "RGB帧分辨率宽度: " << student.car.camera.rgbResolutionWidth<<endl;
        studentCarFile << "RGB帧分辨率高度: " << student.car.camera.rgbResolutionHeight<<endl;
        studentCarFile << "RGB帧率: " << student.car.camera.rgbFrameRate << "fps" << endl;
        studentCarFile << "水平视场角: " << student.car.camera.fovHorizontal<<endl;
        studentCarFile << "垂直视场角: " << student.car.camera.fovVertical<<endl;
        studentCarFile << "深度帧率: " << student.car.camera.depthFrameRate << "fps" << endl;
        studentCarFile << "多线激光雷达型号: " << student.car.lidar.model << endl;
        studentCarFile << "通道数: " << student.car.lidar.channels << endl;
        studentCarFile << "测试范围: " << student.car.lidar.range << "m" << endl;
        studentCarFile << "功耗: " << student.car.lidar.power << "W" << endl;
        studentCarFile << "9轴陀螺仪型号: " << student.car.gyroscope.model << ", 厂家: " << student.car.gyroscope.manufacturer << endl;
        studentCarFile << "液晶显示屏尺寸: " << student.car.green.size << "英寸" << endl;
        studentCarFile << "液晶显示屏型号: " << student.car.green.model << endl;
        studentCarFile << "电池电压: " << student.car.battery.voltage << "V" << endl;
        studentCarFile << "电池容量: " << student.car.battery.capacity << endl;
        studentCarFile << "对外供电电压: " << student.car.battery.supplyVoltage << "V" << endl;
        studentCarFile << "充电时长: " << student.car.battery.chargingTime << "小时" << endl;
        studentCarFile << "----------------------------------------" << endl;
    }
    studentCarFile.close();  // 关闭文件流
}